package com.yxb.request.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.request.domain.ParentRequest;
import com.yxb.request.service.IParentRequestService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 家长发布的辅导需求Controller
 * 
 * @author 林德炫
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/request/request")
public class ParentRequestController extends BaseController
{
    @Autowired
    private IParentRequestService parentRequestService;

    /**
     * 查询家长发布的辅导需求列表
     */
    @PreAuthorize("@ss.hasPermi('request:request:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParentRequest parentRequest)
    {
        startPage();
        List<ParentRequest> list = parentRequestService.selectParentRequestList(parentRequest);
        return getDataTable(list);
    }

    /**
     * 导出家长发布的辅导需求列表
     */
    @PreAuthorize("@ss.hasPermi('request:request:export')")
    @Log(title = "家长发布的辅导需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParentRequest parentRequest)
    {
        List<ParentRequest> list = parentRequestService.selectParentRequestList(parentRequest);
        ExcelUtil<ParentRequest> util = new ExcelUtil<ParentRequest>(ParentRequest.class);
        util.exportExcel(response, list, "家长发布的辅导需求数据");
    }

    /**
     * 获取家长发布的辅导需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('request:request:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(parentRequestService.selectParentRequestByRequestId(requestId));
    }

    /**
     * 新增家长发布的辅导需求
     */
    @PreAuthorize("@ss.hasPermi('request:request:add')")
    @Log(title = "家长发布的辅导需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParentRequest parentRequest)
    {
        return toAjax(parentRequestService.insertParentRequest(parentRequest));
    }

    /**
     * 修改家长发布的辅导需求
     */
    @PreAuthorize("@ss.hasPermi('request:request:edit')")
    @Log(title = "家长发布的辅导需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParentRequest parentRequest)
    {
        return toAjax(parentRequestService.updateParentRequest(parentRequest));
    }

    /**
     * 删除家长发布的辅导需求
     */
    @PreAuthorize("@ss.hasPermi('request:request:remove')")
    @Log(title = "家长发布的辅导需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(parentRequestService.deleteParentRequestByRequestIds(requestIds));
    }
}
